<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title></title>
	<link rel="shortcut icon" href="../../../favicon.ico" />
	<link href="../../../../../Public/source/layui/css/layui.css" rel="stylesheet" />
	<style>
		.form input {
			font-size: medium;
		}

		#alterinfo1 {
			width: 500px;
			height: 60px;
			font-size: 18px;
			margin: 10px auto;
		}

		#alterinfo2 {
			width: 500px;
			height: 60px;
			font-size: 18px;
			margin: 10px auto;
		}

		#alterinfo3 {
			width: 500px;
			height: 60px;
			font-size: 18px;
			margin: 10px auto;
		}

		#alterinfo4 {
			width: 500px;
			height: 60px;
			font-size: 18px;
			margin: 15px auto;
		}

		.form-but {
			width: 500px;
			height: 60px;
			font-size: 18px;
			margin: 10px auto;
		}

		#button-group {
			margin: 10px;
			margin-left: 20%;
			width: 400px;
			height: 50px;
		}
	</style>
	<script>
		function check1() {
			var u = document.getElementById("addtitle");
			var t = document.getElementById("tip1");
			var reg = /^[a-zA-Z]$/;
			if (u == null || u.value.length == 0) {
				t.innerHTML = " 必填, 不能为空";
			}
		}
		function check2() {
			var u = document.getElementById("addcontent");
			var t = document.getElementById("tip2");
			if (u == null || u.value.length == 0) {
				t.innerHTML = " 选填";
			}
		}
		function check3() {
			var u = document.getElementById("addtime");
			var t = document.getElementById("tip3");
			if (u == null || u.value.length == 0) {
				t.innerHTML = "请选择上传日期";
			}
			else {
				t.innerHTML = "OK";
			}
		}
		function check4() {
            var u = document.getElementById("score");
            var t = document.getElementById("tip4");
            var reg = /^[a-zA-Z]$/;
            if (u == null || u.value.length == 0) {
                t.innerHTML = " 不能为空";
            }
        }
		function check() {

		}
		function Clear() {
			console.log("fdgfdgdf");
			var u = document.getElementById("addtitle");
            var v = document.getElementById("addcontent");
            var t = document.getElementById("addtime");
            var w = document.getElementById("score");
            u.value = '';
            v.value = '';
            t.value = '';
            w.value = '';
		}
	</script>
</head>

<body>
	<div class="layui-body">
		<div class="form">
			<div class="layui-form-item" id="alterinfo1">
				<label class="layui-form-label" for="addtitle">标 &emsp; 题:</label>
				<div class="layui-input-inline" style="display: inline-block;">
					<input type="text" class="layui-input" id="addtitle" size="20" style="height: 35px;" placeholder="请输入标题" onblur="check1()"
					/> &ensp;
					<span id="tip1" style="color: #18BC9C; font-size: small;">*</span>
				</div>
			</div>

			<div class="layui-form-item" id="alterinfo2">
				<label class="layui-form-label" for="addcontent">内 &emsp; 容:</label>
				<div class="layui-input-inline" style="display: inline-block;">
					<input type="text" class="layui-input" id="addcontent" size="20" style="height: 35px;" placeholder="请输入内容" onblur="check2()"
					/> &ensp;
					<span id="tip2" style="color: #18BC9C; font-size: small;">*</span>
				</div>
			</div>

			<div class="layui-form-item" id="alterinfo3">
				<label class="layui-form-label" for="addtime">日 &emsp; 期:</label>
				<div class="layui-input-inline" style="display: inline-block;">
					<input type="date" class="layui-input" id="addtime" size="35" style="height: 35px;" onblur="check3()" /> &ensp;
					<span id="tip3" style="color: #18BC9C; font-size: small;">*</span>
				</div>
			</div>

			<div class="layui-form-item" id="alterinfo4">
                <label class="layui-form-label" for="score">评 &emsp; 分:</label>
                <div class="layui-input-inline" style="display: inline-block;">
                    <select name="score" id="score" lay-verify="required" style="width: 190px;height: 35px;border:1px solid lightgrey" onblur="check4()">
                        <option value="">请选择得分</option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                    </select>
                    <span id="tip4" style="color: #18BC9C; font-size: small;">*</span>
                </div>
			</div>
			
			<div class="layui-form-item" id="alterinfo5">
				<label class="layui-form-label">文 &emsp; 件:</label>
				<div class="layui-input-inline">
					<button type="button" class="layui-btn" id="addfile">
						<i class="layui-icon">&#xe67c;</i>上传文件
					</button>	
				</div>
			</div>
			<input type="hidden" id="savename">
			<input type="hidden" id="startname">
			<div class="form-but">
				<div class="layui-btn-group" id="button-group" style="position: relative;top:-10px;">
					<button id="save" class="layui-btn" >添加</button>
					<button id="delete" class="layui-btn" onclick="Clear()">重置</button>
				</div>
			</div>
		</div>
</body>
<script src="../../../../../Public/source/layui/layui.js" type="text/javascript"></script>

<script>  
	layui.use('upload', function () {
		var upload = layui.upload;
		var uploadInst = upload.render({
			elem: '#addfile',//绑定元素
			url: '__URL__/upload', //上传接口
			accept: "file",
			done: function (data) {
				$('#startname').val(data.startname);
				$('#savename').val(data.savename);
			},
			error: function () {
				alert('error');
			}
		});
	});
</script>

<script type="text/javascript" src="../../../../../Public/source/jquery-3.2.1.js"></script>
<script type="text/javascript">
	$.ajax({
		async: true,
		type: "post",
		dataType: "json",
		url: "__URL__/getAlterNote/id/{$result.id}",
		data: {},
		success: function (data) {
			$('#addtitle').val(data.title);
			$('#addcontent').val(data.content);
			$('#addtime').val(data.time);
			$('#score').val(data.score);
			$('#startname').val(data.file);
			$('#savename').val(data.savefile);
		},
		error: function (data) {
			alert('error');
		}
	});
</script>

<script type="text/javascript" src="../../../../../Public/source/jquery-3.2.1.js"></script>
<script type="text/javascript">
	$(function () {
		$('#save').click(function () {
			var u = document.getElementById("addtitle");
			var v = document.getElementById("addtime");
			var w = document.getElementById("score");
			if (u == null || u.value.length == 0 || v == null || v.value.length == 0 ||w==null || w.value.length==0 ){
				alert("请检查信息是否填写完整!");
				return false;
			}
			else {
				var title = $('#addtitle').val();
				var content = $('#addcontent').val();
				var time = $('#addtime').val();
				var score=$('#score').val();
				var startname = $('#startname').val();
				var savename = $('#savename').val();
				$.ajax({
					async: false,
					type: 'post',
					dataType: 'json',
					url: '__URL__/alterNote/id/{$result.id}',//后台提供接口
					data: {
						title: title,
						content: content,
						time: time,
						score:score,
						startname: startname,
						savename: savename
					},
					success: function (data) {
						if (data.status == 1) {
							alert('修改成功');
							window.parent.location.reload();
							var index = parent.layer.getFrameIndex(window.name);
							parent.layer.close(index);
						}
						else {
							alert(data.info);
						}
					},
					error: function (data) {
						alert('error');
					}
				});
				return true;
			}


		});
	})
</script>

</html>